// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import "babel-polyfill"
import Vue from 'vue'
import Vuex from 'vuex'
import store from './store'
import router from './router'
import './assets/css/globle.css' //公共样式
import './assets/font/iconfont.css' //字体图标
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
import VueContextMenu from 'vue-contextmenu'
// import vcolorpicker from 'vcolorpicker'
import promise from 'es6-promise'
import { $Api } from '@/services/api'
import common from '@/services/common'
Vue.prototype.$common = common
import App from './App'

promise.polyfill()
Vue.use(Vuex)
Vue.prototype.$store = store

Vue.use(Antd)
Vue.use(VueContextMenu)
// Vue.use(vcolorpicker)
Vue.use(ElementUI)
import request from './assets/js/request' //可以汉字  自定义公共组件
Vue.use(request)
Vue.config.productionTip = false
import axios from 'axios';
Vue.prototype.$axios = axios;
Vue.prototype.$Api = $Api

import {
  post,
  get,
  delet,
  put
} from './assets/js/ajax' // axios封装的post和get
Vue.prototype.$post = post;
Vue.prototype.$get = get;
Vue.prototype.$delete = delet;
Vue.prototype.$put = put;

router.beforeEach((to, from, next) => {
  if (to.meta.auth) { //判断该路由是否需要登录权限
    // 对路由进行验证
    if (localStorage.getItem('loginToken')) { // 已经登陆
      if (from.name && to.name == "shixiang11")
        localStorage.setItem('router', from.name);
      next()
    } else {
      localStorage.setItem('auto', from.path);
      router.push({
        name: '/login'
      });
    }
    var deviceWidth = document.documentElement.clientWidth;
    if (to.name == '/login' || to.name == '/hello') {
      document.querySelector('html').setAttribute('style', 'font-size:' + deviceWidth / 19.2 + 'px')
    }
  } else {
    var deviceWidth = document.documentElement.clientWidth;
    next()
    if (to.name == '/login' || to.name == '/hello') {
      localStorage.setItem('auto', from.path);
      document.querySelector('html').setAttribute('style', 'font-size:' + deviceWidth / 19.2 + 'px')
    }
  }
})

window.vm = new Vue({
  el: '#app',
  router: router,
  components: {
    App
  },
  template: '<App/>'
})
